package com.fr.base.dav;

import com.fr.base.core.ComparatorUtils;
import com.fr.base.xml.XMLPrintWriter;
import com.fr.base.xml.XMLReadable;
import com.fr.base.xml.XMLableReader;
import java.io.Serializable;

public class FileNode
  implements XMLReadable, Serializable, Cloneable
{
  protected boolean isDirectory;
  protected String envPath;
  protected String lock;

  public FileNode()
  {
  }

  public FileNode(String paramString, boolean paramBoolean)
  {
    this.envPath = paramString;
    this.isDirectory = paramBoolean;
  }

  public String getName()
  {
    if (this.envPath == null)
      return null;
    int i = this.envPath.lastIndexOf("/");
    if (i < 0)
      return this.envPath;
    return this.envPath.substring(i + 1);
  }

  public boolean isDirectory()
  {
    return this.isDirectory;
  }

  public void setDirectory(boolean paramBoolean)
  {
    this.isDirectory = paramBoolean;
  }

  public String getEnvPath()
  {
    return this.envPath;
  }

  public void setEnvPath(String paramString)
  {
    this.envPath = paramString;
  }

  public String getLock()
  {
    return this.lock;
  }

  public void setLock(String paramString)
  {
    this.lock = paramString;
  }

  public String getParent()
  {
    int i = this.envPath.lastIndexOf("/");
    return this.envPath.substring(0, i);
  }

  public boolean equals(Object paramObject)
  {
    if (!(paramObject instanceof FileNode))
      return false;
    return ((((FileNode)paramObject).isDirectory == this.isDirectory) && (ComparatorUtils.equals(((FileNode)paramObject).envPath, this.envPath)) && (ComparatorUtils.equals(((FileNode)paramObject).lock, this.lock)));
  }

  public void readXML(XMLableReader paramXMLableReader)
  {
    if (paramXMLableReader.isAttr())
    {
      String str;
      if ((str = paramXMLableReader.getAttr("isDir")) != null)
        setDirectory(Boolean.valueOf(str).booleanValue());
      if ((str = paramXMLableReader.getAttr("envPath")) != null)
        setEnvPath(str);
      if ((str = paramXMLableReader.getAttr("lock")) != null)
        setLock(str);
    }
  }

  public void writeXML(XMLPrintWriter paramXMLPrintWriter)
  {
    paramXMLPrintWriter.startTAG("Node").attr("isDir", isDirectory()).attr("envPath", getEnvPath());
    if (getLock() != null)
      paramXMLPrintWriter.attr("lock", getLock());
    paramXMLPrintWriter.end();
  }

  public String toString()
  {
    String str = getName();
    if (this.lock != null)
      str = str + "(locked by " + this.lock + ")";
    return str;
  }
}